package com.bbx.taxi.client.Util;

import android.content.Context;
import android.widget.TextView;

import com.bbx.taxi.client.R;

/**
 * @Path com.bbx.taxi.client.Util.CouponUtils.java
 * @Author 严旭文
 * @Date 2016-5-9 下午3:27:22
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class CouponUtils {
	/**
	 * 获取优惠劵的一些特殊标记
	 */
	public static String getMark(Context context, String paymode, boolean menu) {
		String str_mark = "";
		int int_mark;
		try {
			int_mark = Integer.parseInt(paymode);
			if (int_mark == 1) {
				str_mark = context.getString(menu ? R.string.coupon_online
						: R.string.coupon_online2);
			}
		} catch (Exception e) {
		}
		return str_mark;
	}

	/**
	 * 判断优惠劵是否是在线支付专享
	 */
	public static boolean isMarkOnline(String paymode) {
		int int_mark = 0;
		try{int_mark = Integer.parseInt(paymode);}catch(Exception e){}
		if (int_mark == 1) {
			return true;
		}
		return false;
	}

	public final static int coupon_type_0 = 0;// 抵用券
	public final static int coupon_type_1 = 1;// 折扣券
	public final static int coupon_type_2 = 2;// 体验券
	public final static int coupon_type_3 = 3;// 随机卷

	/**
	 * 根据优惠劵类型设置sum
	 */
	public static void setCouponType(Context context, TextView tv_type,
			TextView tv_money, TextView tv_unit, int type) {
		Integer[] str_type = new Integer[] { R.string.coupon_type_0,
				R.string.coupon_type_1, R.string.coupon_type_2 ,R.string.coupon_type_3};
		try{tv_type.setText(context.getString(str_type[type]));}catch(Exception e){}
		// 折扣卷
		if (type == coupon_type_1) {
			String sum=Double.parseDouble(tv_money.getText().toString())/10+"";
			try{
			int decimal=Integer.parseInt(sum.split("\\.")[1]);
			if(decimal==0){
				sum=sum.split("\\.")[0];
			}
			}catch(Exception e){}
			tv_money.setText(sum);
			tv_unit.setText(context.getString(R.string.unit_zhekou));
		} else {
			tv_unit.setText(context.getString(R.string.unit_yuan));
		}
	}

	/**
	 * 判断是否是折扣卷
	 */
	public static boolean isZhekou(int type) {
		// 折扣卷
		if (type == coupon_type_1) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 获取折扣几元，price为分,zhekou元
	 * 返回分
	 */
	public static double getZhekouSum(double price,double zhekou){
		return Double.parseDouble(FormatUtil.onFormatPrice(price*(1-(zhekou/100))));
	}
	/**
	 * price为分
	 * 体验卷，返回优惠多少元，coupon_sum元
	 */
	public static double getTiyanSum(double price,double coupon_sum){
		double coupon=Double.parseDouble(FormatUtil.onFormatPrice(price))-coupon_sum;
		if(coupon<0)coupon=0;
		return coupon;
	}
}
